﻿using System;
using Microsoft.Xna.Framework;

class ObjectFollowingEnemy : PatrollingEnemy
{
    GameObject target;
    public override void Update(GameTime gameTime)
    {
        if (target == null)
        {
            GameObjectList gameWorld = Root as GameObjectList;
            target = gameWorld.Find("player") as Player;
        }
        float direction = target.Position.X - position.X;
        if (Math.Sign(direction) != Math.Sign(velocity.X) && target.Velocity.X != 0.0f && velocity.X != 0.0f)
            TurnAround();
        base.Update(gameTime);
    }
    public void SetTarget(GameObject target)
    {
        this.target = target;
    }
}

